﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QLPKWeb.Models.FormBean.PhanQuyen.DepartmentsForm>" %>

<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
<%@ Import Namespace="DONGACS.DTO" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript" language="javascript" src="<%= ResolveUrl("~/Content/Scripts/Departments/Departments.js") %>"></script>
    <script language="javascript" type="text/javascript">
        


        $(document).ready(function() {
            selectMenu("system-Departments");
            $("#DepartmentsSearch").focus();
        });
        
        $(function () {
            $("#box").dialog({
                autoOpen: false,
                modal: true,
                width: 400
            });

            $("#opener").click(function () {
                $("#box").dialog("open");
                return false;
            });
        });
    </script>
    <form id="form" method="post" action="#">

    <%=Html.Hidden("DepartmentID")%>
    <input type="hidden" id="IdChief" name="IdChief"/> <%--Chứa Id của user đựoc chọn làm Trưởng phòng--%>

   <div class="box round first fullpage">
            <h4> Quản lý Phòng ban</h4>
            
            <table class="table_outsite">
                    
                    <tr>
                        <td >
                            <%--Thông Báo--%>
                            <%
                                if (Model.MessageCreateDepartments != null)
                                {
                            %>
                            <div id="MessageCreateDepartments" style="font-size: 12px; color: Blue; font-weight: bold">
                                <%=Model.MessageCreateDepartments %></div>
                            <%
                                }
                            %>
                            <%
                                if (Model.MessageEditDepartments != null)
                                {
                            %>
                            <div id="MessageEditDepartments" style="font-size: 12px; color: Blue; font-weight: bold">
                                <%=Model.MessageEditDepartments %></div>
                            <%
                                }
                            %>
                            <%--end--%>
                        </td>
                        <td  style="padding-top:10px;text-align: right; width: 100%;">
                            <input type="button" class="btn btn-grey"value="Tạo/Cập nhật" onclick="DoCreateOrEdit()" />
                            <input type="button" class="btn btn-grey"value="Tạo mới" onclick="javascript:DoNewAjax();" />
                            <input type="button" class="btn btn-grey"value="Xóa" onclick="javascript:DoDelete();" />
                            <input type="button" class="btn btn-grey"value="Nhập lại" onclick="javascript:DoReset();" />
                        </td>
                    </tr>
                </table >
                <table class="form">
                    <tr>
                        <td nowrap="nowrap">
                            Mã phòng ban :
                        </td>
                        <td colspan="2">
                            <input type="text" name="ID" id="ID" readonly="readonly" value='<%=Model.ID %>' width="70%" />
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 10%" nowrap="nowrap">
                            Ngày tạo:
                        </td>
                        <td style="width: 15%">
                            <input  type="text"name="CreateDate" id="CreateDate"  width="70%" disabled="disabled"  value="<%=Model.CreateDate.ToString("dd/MM/yyyy")%>" />
                        </td>
                        <td style="width: 1%" nowrap="nowrap">
                            <b>Tên phòng ban:</b>
                        </td>
                        <td style="width: 38%">
                            <input type="text" style="width:50%" value="<%=Model.DepartmentName%>" id="DepartmentName" name="DepartmentName" />
                                
                            <div id="DepartmentNameMessage" class="red"></div>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap="nowrap">
                            Ngày cập nhật:
                        </td>
                        <td>
                            <input type="text" width="70%" id="UpdateDate" disabled="disabled" value='<%=Model.UpdateDate.ToString("dd/MM/yyyy")%>' />
                        </td>
                        <td nowrap="nowrap">
                            <b>Mô tả:</b>
                        </td>
                        <td>
                            <input type="text"  style="width:50%" id="DepartmentDesc" name="DepartmentDesc" value="<%=Model.DepartmentDesc%>"/>
                        </td>
                    </tr>
                    <tr>
                        <td nowrap="nowrap">
                            Người tạo:
                        </td>
                        <td>
                            <input type="text"  name="CreateBy" id="CreateBy" width="70%" disabled="disabled" value="<%=Model.CreateByUser%>" />
                        </td>
                        <td nowrap="nowrap" style="display: none">
                           <b>Trưởng phòng:</b>
                        </td>
                        <td style="display: none">
                            <input type="text"  style="width:40%" id="Chief" name="Chief" readonly="readonly" value="<%=Model.Chief%>" />
                            <input   class="btn btn-grey"type="button" id="opener" name="opener" value="Chọn..." onclick="nhanko()" />
                           
                        </td>
                    </tr>
                    <tr>
                        <td nowrap="nowrap">
                            Người cập nhật:
                        </td>
                        <td>
                            <input type="text" width="70%" id="UpdateBy" disabled="disabled" value='<%=Model.UpdateByUser%>' />
                        </td>
                    </tr>
                </table>
            
          
            <table  class="table table-striped table-bordered dataTable" id="example">
                <tr>
                    <td colspan="2" class="first"  style="width: 100%">
                     Danh sách Phòng ban   <span style="float: right">  <%=Html.TextBox("DepartmentsSearch")%>
                        <img onclick="javascript:doSearch();" style="vertical-align: middle; cursor:pointer" src="<%=ResolveUrl("~/Content/img/search_icon.gif")%>"
                            alt="Departments Search" title="Departments Search"/></span>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <table cellspacing="0" cellpadding="0"  class="table">
                            <tr class="title">
                                <td style="border: 1px solid #ddd "width="8%" class="first">
                                    &nbsp;<strong>Mã</strong>
                                </td>
                                <td style="border: 1px solid #ddd "nowrap="nowrap">
                                    <strong>Tên phòng ban</strong>
                                </td>
                                <td style="border: 1px solid #ddd "align="left" nowrap="nowrap">
                                    <strong>Mô tả</strong>
                                </td>
                                <td style="border: 1px solid #ddd "width="12%" nowrap="nowrap">
                                    <strong>Ngày cập nhật</strong>
                                </td>
                                <td style="border: 1px solid #ddd "class="last" nowrap="nowrap">
                                    <strong>Người cập nhật</strong>
                                </td>
                            </tr>
                            <%--Departments List--%>
                            <%
                                
                           IList<DepartmentsDto> DepartmentsDtoList = Model.DepartmentsPagedList;

                           foreach (DepartmentsDto dto in DepartmentsDtoList)
                            {
                            %>
                            <tr class="item_row" onclick="javascript:highlight(this);EditDepartmentsAjax(<%=dto.ID%>);">
                                <td style="border: 1px solid #ddd "class="first" align="left">
                                    &nbsp;<%=dto.ID%>
                                </td>
                                <td style="border: 1px solid #ddd "align="left">
                                    <%=dto.DepartmentName%>&nbsp;
                                </td>
                                <td style="border: 1px solid #ddd "align="left">
                                    <%=dto.DepartmentDesc %>
                                </td>
                                <td style="border: 1px solid #ddd "align="left">
                                    <%=dto.UpdateDate.ToString("dd/MM/yyyy")%>&nbsp;
                                </td>
                                <td style="border: 1px solid #ddd "class="last">
                                    <%=dto.UpdateByUser%>&nbsp;
                                </td>
                            </tr>
                            <%}
                            %>
                            <tr class="border_bottom">
                                <td class="first" style="background: #DDDDDD">
                                </td>
                                <td class="last" colspan="7" align="right" style="background: #DDDDDD; padding-right: 10px">
                                     <%
                                     PagerOptions pagerOptions = new PagerOptions();
                                     pagerOptions.PageIndexParameterName = "id";
                                     pagerOptions.NextPageText = "Tiếp";
                                     %>
                                    <div><%=Html.Pager(Model.DepartmentsPagedList,pagerOptions) %></div>
                                    <%=Html.Hidden("PageNumber", Model.PageNumber)%>
                                </td>
                            </tr>
                            <%--dã xóa--%>
                        </table>
                    </td>
                </tr>
            </table>
            
           
      
    </div>
    <%--<%Html.EndForm(); %>--%>

    </form>
    
    

    <%-- Box chọn trưởng phòng --%>
    <div title="Chọn Trưởng Phòng" id="box" style="display: none">              
        <form id = "form1" method="post" action="<%=ResolveUrl("") %>" target="_parent">
            <div style="margin: 0px 0px 5px 5px"></div>
                <table class="table_input">
                    <tr>
                        <td>
                            <%
                            if(Model.IdChiefList.Count() > 7)
                            {
                            %>
                            <div style='width:100%; height:440px; overflow:auto'>   
                            <%    
                            }
                            else
                            {
                            %>
                            <div style='width:100%; height:auto; overflow:auto'>   
                            <%
                            }
                            %>
                                <table width="100%">                            
                                    <%
                                        for (int i = 0; i < Model.IdChiefList.Count(); i++)
                                        {
                                            var item = Model.IdChiefList.ElementAt(i);
                                        %>
                                                <tr>
                                                                                  
                                            <td width="5%">
                                                <input type="radio" id="Radio" name="RadioTruongPhong" value="<%=item.ID %>"/>
                                            </td>
                                            <td width="45%">
                                                <%= (string.IsNullOrEmpty(item.LastName) || string.IsNullOrEmpty(item.FirstName)) ? item.UserName : item.LastName%> <%=item.FirstName%>
                                            </td>
                                            
                                                </tr>
                                                                            
                                        <%
                                        }     
                                        %>
                                </table>  
                            </div>
                        </td>
                    </tr>
                </table>
            <br/>
            <div align="right">
                <input type="button" name="cancel" value="Đồng ý" onclick="javascript:DoChonTruongPhong();"/>&nbsp;
                <input type="button" name="cancel" value="Hủy thao tác" onclick="javascript:$('#box').dialog('close');"/>
            </div>
        </form>
    </div>
    

</asp:Content>
